package cn.xspace.wnx.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.xspace.android.xafcommon.base.BaseActivity;

import cn.xspace.app.view.TitleBar;
import cn.xspace.chatui.bean.MsgRecordEntity;
import cn.xspace.library.util.BldNavigation;
import cn.xspace.wnx.R;
import cn.xspace.wnx.fragment.MyGroupsFragment;
import cn.xspace.wnx.util.Navigator;

/**
 * Created by liuchen on 2016/10/31.
 */

public class GroupListActivity extends BaseActivity {
    private static final String TAG = "GroupListActivity";
    private MsgRecordEntity recordEntity;
    private TitleBar mTitle_bar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void getIntentData() {
        super.getIntentData();
        Bundle mBundle = getIntent().getBundleExtra(BldNavigation.KEY_BUNDLER);
        if (mBundle != null) {
            recordEntity = (MsgRecordEntity) mBundle.getSerializable(MsgForwardActivity.FORWARD_ENTITY);
        }
    }

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.activity_group_chat_list);
    }

    @Override
    protected void initFindViewById() {
        super.initFindViewById();
        mTitle_bar = (TitleBar) findViewById(R.id.title_bar);
        Bundle mBundle = null;
        if (recordEntity != null) {
            mBundle = new Bundle();
            mBundle.putSerializable(MsgForwardActivity.FORWARD_ENTITY, recordEntity);
        }
        MyGroupsFragment fragment = new MyGroupsFragment();
        if (mBundle != null) {
            fragment.setArguments(mBundle);
        }
        FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
        trans.replace(R.id.container, fragment, TAG);
        trans.commitAllowingStateLoss();
    }

    @Override
    protected void initData() {
        super.initData();
    }


    @Override
    protected void initEvent() {
        super.initEvent();
        mTitle_bar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTitle_bar.setTitle(getResources().getString(R.string.group_mine));
        mTitle_bar.setRightLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Navigator.startNewChatActivity(mContext, null);
            }
        });
    }

//    @Override //暂时不需要这么做
//    public void onEventMainThread(Map<String, Object> inParam) {
//        LogUtil.d(TAG, "wubaojie>>>onEventMainThread: inParam :" + inParam);
//        if (EventBusConstant.FINISH_PAGE_FORWARD.equals(inParam.get(EventBusConstant.TYPE)) && recordEntity != null) {
//            finish();
//        }
//    }

    public enum GroupType {
        Normal(0),
        Organization(3),
        Professional(2);
        int num;

        GroupType(int type) {
            num = type;
        }

        public int getNum() {
            return num;
        }
    }

}
